package com.ljb.lib_ar;

import android.app.Activity;
import android.content.Context;
import android.util.Log;

import cn.easyar.Engine;

/**
 * @author ljb
 * @des
 * @date 2019/11/16
 */
public class EasyAR {
    private static final String TAG = "EasyAR";
    private static final String key = "J6g/UCO7J0w72vTib3DPxStU9cJAQtfQ4T4XKxeaCXsjig9mF4cYK1jLWTlX21o9UtBVSROYQmoNhE4lQIQNehaMHkIHkCVtQNNdJUCFBWoHhx9sEctWUhnLDnwMjQBsK40fK1iyTmoNhEJlCItCaBCNCWQNy0ArQLRAKxSIHmADhxh6QNM3KwCIH2AByzElQJkAaBaPA3sPmk4zOcsbYAyNA34Ry0ArD4gPKz/FTmwamQV7B70FZAe6GGgPmU4zDJwAZU7LBXouhg9oDstWbwOFH2wfxRcrAJwCbQ6MJW0Ry1ZSQIoDZEyFBmtMiB5tB4QDKz/FTn8DmwVoDJ0fK1iyTmsDmgVqQLRAKxKFDX0Ehh5kEctWUkCIAm0QhgVtQLRAKweRHGAQjDhgD4w/fQOEHCtYhxllDsVOYBGlA2oDhU4zBIgAegeUQHJAixlnBoUJQAaaTjM5y05UTssaaBCADWcWmk4zOcsOaBGADys/xU55DogYbw2bAXpA0zcrC4YfKz/FTmwamQV7B70FZAe6GGgPmU4zDJwAZU7LBXouhg9oDstWbwOFH2wftBFRcbKWrUKRifS7USFg5oj0dmBVsSWwwffhiVgf7v1ypNIGGGcoRiOsUn+MX6m00IddLBPmuE5kwk8qBPqvBoMWuzVB+tIydpWXNu/TSSgcSVmT77ZlM+rx8Hvb2eV7kp7KFNbm1mmMkTmxXe7mHpvhAXtfCRkMaehC2CZLx+6lXiVIdKliMWE4Lu97UY2+wvE3Tdo589Opjyt3EqrT66hnHPB2CUTAh9wIMEwdayuo+t93y961V3Jqzgriv89d8GEfvSCxWNL6bVzniZEeUbIaWZaEDrqTqQlD9WGFv/nMe8IIHokdRAPEWQMNa7F+7bAaItbNBtQmTs/vT9Vi6WwJ";

    private static EasyAR instance;
    private static ArView arView;
    private String path;
    private OnTargetChangeListener onTargetChangeListener;

    private EasyAR(Activity activity) {
        //初始化SDK
        boolean initialize = Engine.initialize(activity, key);
        Log.e(TAG, "onCreate: EasyAR初始化 " + initialize);
        if (!initialize) {
            Log.e(TAG, Engine.errorMessage());
        }
    }

    /**
     * 获取默认对象
     * @param activity
     * @return
     */
    public static EasyAR getDefault(Activity activity) {
        if (instance == null) {
            synchronized (EasyAR.class) {
                if (instance == null) {
                    instance = new EasyAR(activity);
                }
            }
        }
        return instance;
    }

    /**
     * 设置目标Target路径
     *
     * @param path
     * @return
     */
    public EasyAR setTarget(String path) {
        this.path = path;
        return this;
    }

    /**
     * 设置发现Target时的回调
     *
     * @param onTargetChangeListener
     * @return
     */
    public EasyAR setOnTargetChangeListener(OnTargetChangeListener onTargetChangeListener) {
        this.onTargetChangeListener = onTargetChangeListener;
        return this;
    }

    /**
     * 创建ARView
     *
     * @param context
     * @return
     */
    public ArView create(Context context) {
        ArView arView = new ArView(context);
        arView.setTargetPath(path);
        arView.setOnTargetChangeListener(onTargetChangeListener);
        return arView;
    }

}
